# File description -------------------------------------------------------------

# Replication file: Paper

# Title: Right-wing terror, media backlash, and voting preferences for the far right
# Authors: Alexander De Juan, Felix Haass, Julian Voss

# Date: 01.05.2025


# Load libraries ----------------------------------------------------------

library(tidyverse)
library(ggrepel)
library(patchwork)
library(fixest)
library(broom)
library(haven)
library(ggtext)


# Load data ---------------------------------------------------------------

rtv_timeline_ag <- read_rds("./data/rtv_timeline_ag.rds")
voting_timeline_data <- read_rds("./data/voting_timeline_data.rds")
fb_2019_2020_models <- read_rds("./data/forsa_data_hanau.rds")
bilendi_survey <- read_rds("./data/bilendi_survey.rds")
genios_data_hanau <- read_rds("./data/genios_data_hanau.rds")
facebook_data <- read_rds("./data/facebook_data.rds")
rtv_cases <- read_rds("./data/rtv_cases.rds")
forsa_rtv_data <- read_rds("./data/forsa_rtv_data.rds")

# Figure 2: Right-wing voting and violence in Germany ---------------------


## Panel A: Violence over time ------------------------------------------------------


# define colors and jitter widths
col_cols <- c( "grey30", "#a61c3c")  # "#84BD00FF", "#FFCD00FF") %
fill_cols <- c( "grey30", "#a61c3c")  #"#84BD00FF", "#FFCD00FF")
width_jitter = 0.25
height_jitter = 0


violence_timeline_plot <- ggplot(rtv_timeline_ag, 
                                 aes(x = date, 
                                     y = all_victims)) + 
  
  ggrepel::geom_label_repel(data = rtv_timeline_ag %>% 
                              filter(grepl("Hanau", city)) %>% 
                              mutate(killed = as.numeric(n_killed)), 
                            aes(x = floor_date(as.Date(ymd) , "month"), 
                                y = all_victims, 
                                label = city), 
                            nudge_x = -650, 
                            nudge_y = 5, 
                            size = 3.5) + 

  geom_linerange(
    aes(ymin = 0,
        ymax = all_victims,
        alpha = killed_cat,
        color = killed_cat),
    linewidth = 0.35,
    position = position_jitter(seed = 123, 
                               width = width_jitter, 
                               height = height_jitter)) +
  
  # for legend only
  
  geom_point(
    aes(
      fill = killed_cat,
      alpha = killed_cat),
    size = 4, 
    shape = 21,
    color = "grey95",
    stroke = .65,
    position = position_jitter(width = width_jitter,
                               height = height_jitter,
                               seed = 123)) +
  
  
  scale_color_manual("", values = col_cols) +
  scale_fill_manual("", values = fill_cols) +
  scale_alpha_manual("", values = c(0.25, 1)) +
  scale_size("Victims wounded", breaks = c(0, 1, 5), range = c(2, 6), 
             labels = c("0", "1-5", "5+")) + 
  theme_bw() + 
  theme(panel.grid = element_blank(), 
        legend.position = "bottom") +
  labs(
    y = "Victims\n(killed + wounded)", 
    x = "") +
  guides(color = guide_legend(), size = guide_legend())


violence_timeline_plot




## Panel B: Voting over time --------------------------------------------------------




voting_timeline_plot <-  voting_timeline_data %>%  ggplot(., aes(x = year, 
                                                                 y = rw_share)) + 
  geom_line() +
  geom_line(data = voting_timeline_data %>% filter(missing), 
            aes(y = rw_share_inter, 
                color = missing, 
                linetype = missing)) +
  labs(y = "PRRP vote share\n(AfD/REPs/DVU/NPD)", 
       x = "") +
  theme_bw() + 
  theme(panel.grid = element_blank(), 
        legend.position = "none") +
  scale_color_manual("", values = c( "grey80"), labels = c("Data missing")) +
  scale_linetype_manual("", values =c( "dashed"), labels = c("Data missing"))

voting_timeline_plot



## Build final plot --------------------------------------------------------



final_voting_violence_plot <- (voting_timeline_plot + labs(title = "A: Right-wing voting over time")) / 
  (violence_timeline_plot + labs(title = "B: Fatal right-wing attacks over time"))

final_voting_violence_plot 

ggsave(final_voting_violence_plot, filename = "./figures/figure_2_violence_voting.pdf", 
       width = 11, height = 9, scale = .7)


# Figure 3: Media backlash against the AfD --------------------------------

hanau_backlash_genios_plot <-
  genios_data_hanau %>% 
  ggplot(., aes(x = days_since_attack, 
                y =   article_share, 
                color = keywords, 
                linetype = keywords)) +
  geom_vline(xintercept = 0, linetype = "dashed") + 
  geom_line() + 
  labs(x = "Days since attack", 
       y = "Share of newspaper articles\nabout the AfD that mention keywords") +
  theme_bw() + 
  theme(panel.grid = element_blank(), 
        legend.position = "bottom") +
  scale_x_continuous(breaks = c(seq(-15, 15, 5))) +
  scale_color_manual("Keywords:", values = c("black", "grey40"), 
                     labels = c("\"AfD + right-wing\"", 
                                "\"AfD + violence\"")) +
  scale_linetype_manual("Keywords:", 
                        values = c("solid", "dotted"), 
                        labels = c("\"AfD + right-wing\"", 
                                   "\"AfD + violence\"")) 

ggsave("./figures/figure_3_hanau_backlash.pdf", 
       hanau_backlash_genios_plot, width = 9, height = 5.5, scale = .7)

# Figure 4: The Hanau attack and voting intentions-------------------------


## Upper panel: Descriptive analysis --------------------------------------

# define bandwidth
bw <- 15 

# data preparation for plotting
hanau_plot_data <- fb_2019_2020_models %>% 
  filter(days_new %in% c(-bw:bw)) %>% 
  group_by(days_new, date, post_hanau) %>%
  summarise(# n = n(), 
    afd_share_ltw = weighted.mean(ltw_afd_intention, weight1, na.rm =T),
    afd_share_btw = weighted.mean(btw_afd_intention, weight1, na.rm =T)) %>% 
  ungroup() %>% 
  mutate(donut_hole_dates = ifelse(days_new %in% 0:1, T, F)) %>% 
  pivot_longer(cols = -c(days_new, date, post_hanau, donut_hole_dates), 
               names_to = "election_type", 
               values_to = "afd_share") %>% 
  mutate(afd_share = round(afd_share, 2))

# generate plot
hanau_plot_raw <- hanau_plot_data %>% 
  ggplot(., aes(x = days_new, y = afd_share, 
                group = post_hanau)) + 
  geom_line(aes(group = post_hanau)) +
  
  geom_point(size = 2) +
  scale_color_manual(values = c("black", "grey40")) +
  
  geom_vline(xintercept = 0) +
  theme_bw() +
  theme(legend.position = "none", 
        panel.grid = element_blank()) +
  scale_x_continuous(breaks = seq(-bw, bw, 5)) +
  labs(x = "Days before/since attack", 
       y = "Daily average of AfD voting intention", 
       title = "Descriptive analysis") +
  facet_wrap(~election_type, 
             labeller = labeller(election_type = c("afd_share_btw" = "Federal elections", 
                                                   "afd_share_ltw" = "State elections")))


## Lower panel: Treatment effects ------------------------------------------

# define bandwidth and covariates
bw <- 15

covariates <- c(
  "male",
  "bland", 
  "birth_decade", 
  "income", 
  "education", 
  "occupation_status", 
  "sample", 
  "religion", 
  "children", 
  "family_status"
)

# Models

## state elections

hanau_ols_ltw_narrow <- feols(c(ltw_afd_intention) ~ 
                                post_hanau 
                              | sw0(.[covariates]),
                              se = "hetero",
                              data = fb_2019_2020_models %>% 
                                filter(days_new %in% c(-5:4)))


hanau_ols_ltw_tiny <- feols(c(ltw_afd_intention) ~ 
                              post_hanau 
                            | sw0(.[covariates]),
                            se = "hetero",
                            data = fb_2019_2020_models %>% 
                              filter(days_new %in% c(-1:0)))


hanau_ols_ltw_three <- feols(c(ltw_afd_intention) ~ 
                               post_hanau 
                             | sw0(.[covariates]),
                             se = "hetero",
                             data = fb_2019_2020_models %>% 
                               filter(days_new %in% c(-3:2)))

hanau_ols_ltw_broad <- feols(c(ltw_afd_intention) ~ 
                               post_hanau 
                             | sw0(.[covariates]), 
                             se = "hetero",
                             data = fb_2019_2020_models %>% 
                               filter(days_new %in% c(-15:14)))


## federal elections

hanau_ols_btw_narrow <- feols(c(btw_afd_intention) ~ 
                                post_hanau 
                              | sw0(.[covariates]) , 
                              se = "hetero",
                              data = fb_2019_2020_models %>% 
                                filter(days_new %in% c(-5:4)))

hanau_ols_btw_tiny <- feols(c(btw_afd_intention) ~ 
                              post_hanau 
                            | sw0(.[covariates]) , 
                            se = "hetero",
                            data = fb_2019_2020_models %>% 
                              filter(days_new %in% c(-1:0)))


hanau_ols_btw_three <- feols(c(btw_afd_intention) ~ 
                               post_hanau 
                             | sw0(.[covariates]) , 
                             se = "hetero",
                             data = fb_2019_2020_models %>% 
                               filter(days_new %in% c(-3:2)))


hanau_ols_btw_broad <- feols(c(btw_afd_intention) ~ 
                               post_hanau 
                             | sw0(.[covariates])
                             , 
                             se = "hetero",
                             data = fb_2019_2020_models %>% 
                               filter(days_new %in% c(-15:14)))


## Build final plot --------------------------------------------------------


model_list <- list(
  hanau_ols_btw_broad = map_dfr(hanau_ols_btw_broad, tidy, conf.int = T, .id = "cov"), 
  hanau_ols_btw_narrow = map_dfr(hanau_ols_btw_narrow, tidy, conf.int = T, .id = "cov"),
  hanau_ols_btw_tiny = map_dfr(hanau_ols_btw_tiny, tidy, conf.int = T, .id = "cov"),
  hanau_ols_btw_three = map_dfr(hanau_ols_btw_three, tidy, conf.int = T, .id = "cov"),
  
  
  hanau_ols_ltw_broad = map_dfr(hanau_ols_ltw_broad, tidy, conf.int = T, .id = "cov"), 
  hanau_ols_ltw_narrow = map_dfr(hanau_ols_ltw_narrow, tidy, conf.int = T, .id = "cov"), 
  hanau_ols_ltw_tiny = map_dfr(hanau_ols_ltw_tiny, tidy, conf.int = T, .id = "cov"),
  hanau_ols_ltw_three = map_dfr(hanau_ols_ltw_three, tidy, conf.int = T, .id = "cov")
  
  
)

# prepare data for plotting
main_coefplot_data  <- model_list %>% 
  map_dfr(tibble, conf.int = T, .id = "name") %>% 
  filter(!grepl("Intercept", term)) %>% 
  mutate(cov = ifelse(grepl("1", cov), "no covariates", "covariates")) %>% 
  
  separate(name, into = c("place", "model", "election_type", "model_type"), sep = "_")  %>% 
  mutate(x_axis_id = paste0(model, "-", model_type)) %>% 
  filter(term == "post_hanau")

main_coefplot <- ggplot(main_coefplot_data, aes(x = x_axis_id, y = estimate, group = cov, 
                                                color = cov)) + 
  geom_hline(yintercept = 0, linetype = "dashed") + 
  
  
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = 0, size = 0.25, 
                position = position_dodge(width = 0.5), alpha = 0.9) + 
  geom_errorbar(aes(ymin = estimate - 1.67 * std.error, 
                    ymax = estimate + 1.67 * std.error), width = 0, size = 0.75, 
                position = position_dodge(width = 0.5), alpha = 0.9) + 
  geom_point(size = 2.5,
             aes(shape = cov), 
             position = position_dodge(width = 0.5)) + 
  scale_color_manual("", label = c("covariates", "no covariates"),
                     values = c("grey52", "black")) +
  scale_shape_discrete("", label = c("covariates", "no covariates")) +
 
  scale_x_discrete(labels = c("15 days", "5 days",
                              "3 days", "1 day")) +
  theme_bw() + 
  theme(panel.grid = element_blank(), 
        legend.position = "bottom", 
        axis.text.x = element_text(size = 7.5)) +
  labs(x = "\nBandwidth window around the cutoff", y = "Treatment effect estimate", 
       title = "\nTreatment effects") +
  facet_wrap(~election_type, labeller = labeller(election_type = c("btw" ="Federal elections", 
                                                                   "ltw" = "State elections")))


main_paper_plot <- hanau_plot_raw / 
  main_coefplot 

main_paper_plot

ggsave(main_paper_plot, filename = "./figures/figure_4_hanau_voting.pdf", 
       width = 8, height = 10, scale = 0.8)




# Figure 5: The Hanau attack and Facebook followers -----------------------

# State-level models
hanau_ols_state_15d_growth <- feols(like_growth ~ post_hanau,
                                    se = "hetero",
                                    data = facebook_data %>%
                                      filter(date_num_hanau %in% c(-15:14)) %>%
                                      filter(account_type_new == "Land"))

hanau_ols_state_5d_growth <- feols(like_growth ~ post_hanau,
                                   se = "hetero",
                                   data = facebook_data %>%
                                     filter(date_num_hanau %in% c(-5:4)) %>%
                                     filter(account_type_new == "Land"))


hanau_ols_state_3d_growth <- feols(like_growth ~ post_hanau,
                                   se = "hetero",
                                   data = facebook_data %>%
                                     filter(date_num_hanau %in% c(-3:2)) %>%
                                     filter(account_type_new == "Land"))


hanau_ols_state_1d_growth <- feols(like_growth ~ post_hanau,
                                   se = "hetero",
                                   data = facebook_data %>%
                                     filter(date_num_hanau %in% c(-1:0)) %>%
                                     filter(account_type_new == "Land"))

# Federal-level models
hanau_ols_federal_15d_growth <- feols(like_growth ~ post_hanau,
                                      se = "hetero",
                                      data = facebook_data %>%
                                        filter(date_num_hanau %in% c(-15:14)) %>%
                                        filter(account_type_new == "Bund"))

hanau_ols_federal_5d_growth <- feols(like_growth ~ post_hanau,
                                     se = "hetero",
                                     data = facebook_data %>%
                                       filter(date_num_hanau %in% c(-5:4)) %>%
                                       filter(account_type_new == "Bund"))



hanau_ols_federal_3d_growth <- feols(like_growth ~ post_hanau,
                                     se = "hetero",
                                     data = facebook_data %>%
                                       filter(date_num_hanau %in% c(-3:2)) %>%
                                       filter(account_type_new == "Bund"))


hanau_ols_federal_1d_growth <- feols(like_growth ~ post_hanau,
                                     se = "hetero",
                                     data = facebook_data %>%
                                       filter(date_num_hanau %in% c(-1:0)) %>%
                                       filter(account_type_new == "Bund"))

model_list <- list(
  hanau_ols_federal_1d_growth = hanau_ols_federal_1d_growth,
  hanau_ols_federal_3d_growth = hanau_ols_federal_3d_growth,
  hanau_ols_federal_5d_growth = hanau_ols_federal_5d_growth,
  hanau_ols_federal_15d_growth = hanau_ols_federal_15d_growth,
  
  hanau_ols_state_1d_growth = hanau_ols_state_1d_growth,
  hanau_ols_state_3d_growth = hanau_ols_state_3d_growth,
  hanau_ols_state_5d_growth = hanau_ols_state_5d_growth,
  hanau_ols_state_15d_growth = hanau_ols_state_15d_growth
)

# Build plots 

fb_coefplot <- 
  model_list %>%
  map_dfr(broom::tidy, conf.int = T, .id = "name") %>%
  filter(term == "post_hanau") %>%
  separate(name, into = c("place", "model", "account_type", "model_type"), sep = "_") %>%
  mutate(x_axis_id = paste0(model, "-", model_type),
         bandwidth = case_match(model_type, "15d" ~ "15 days", "5d" ~ "5 days",
                                "3d" ~ "3 days", "1d" ~ "1 day"),
         bandwidth = factor(bandwidth, levels = c("15 days", "5 days", "3 days", "1 day")),
         account_type = ifelse(account_type == "state", "State level accounts", "Federal level accounts")) %>%
  ggplot(. , aes(x = bandwidth, y = estimate)) +
  geom_hline(yintercept = 0, linetype = "dashed") +
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = 0, size = 0.25,
                position = position_dodge(width = 0.5), alpha = 0.9) +
  geom_errorbar(aes(ymin = estimate - 1.67 * std.error,
                    ymax = estimate + 1.67 * std.error), width = 0, size = 0.75,
                position = position_dodge(width = 0.5), alpha = 0.9) +
  geom_point(size = 2.5,
             position = position_dodge(width = 0.5)) +
  theme_bw() +
  theme(panel.grid = element_blank(),
        legend.position = "bottom") +
  labs(x = "Bandwidth window around the cutoff", y = "Treatment effect estimate",
       title = "Treatment effects") +
  facet_wrap(~account_type)

fb_descriptive_plot <- 
  facebook_data %>%
  mutate(post_hanau = ifelse(date>as.Date("2020-02-19"), 1, 0),
         date_num_hanau = as.numeric(as.Date(date)) - as.numeric(as.Date("2020-02-20"))) %>%
  filter(date_num_hanau %in% -15:15) %>%
  group_by(date_num_hanau, post_hanau, account_type_new) %>%
  summarise(
    page_likes = mean(page_likes, na.rm = T),
    like_growth = mean(like_growth, na.rm = T)
  ) %>%
  ungroup() %>%
  mutate(account_type_new = ifelse(account_type_new == "Land",
                                   "State level accounts",
                                   "Federal level accounts")) %>%
  ggplot(., aes(x = date_num_hanau, y = page_likes)) +
  geom_line() +
  geom_point(size = 2) +
  scale_color_manual(values = c("black", "grey40")) +
  geom_vline(xintercept = 4, linetype = "dotted") +
  theme_bw() +
  theme(legend.position = "none",
        panel.grid = element_blank()) +
  scale_x_continuous(breaks = seq(-15, 15, 5)) +
  labs(x = "Days before/since attack",
       y = "Daily average followers per page",
       title = "Descriptive analysis") +
  facet_wrap(~account_type_new, scales = "free_y")


fb_combined_plot_hanau <- fb_descriptive_plot / fb_coefplot

ggsave(fb_combined_plot_hanau, filename = "./figures/figure_5_hanau_facebook.pdf",
       width = 8, height = 8, scale = 0.8)

# Figure 6: Survey experiment ---------------------------------------------


# define PAP covariates
cov_full_pap  <- c("male",
                   "age",
                   "factor(education)",
                   "political_interest",
                   
                   "party_preference_pre_1", 
                   "party_preference_pre_2", 
                   "party_preference_pre_3", 
                   "party_preference_pre_4", 
                   "party_preference_pre_5", 
                   "party_preference_pre_6"
)


# estimate models
te_pap_1 <- feols(c(party_preference_post_5, party_programme_5, afd_pref_post) ~ 
                    
                    factor(treatvscontrol)  +
                    
                    sw0(.[cov_full_pap]),
                  data =  bilendi_survey %>% 
                    # keep only those respondents who pass attention check
                    filter(any_correct_remember_plot_fotos >= 1),
                  se = "standard")

te_pap_2 <- feols(c(party_preference_post_5, party_programme_5, afd_pref_post) ~ 
                    
                    factor(treatment)  +
                    
                    sw0(.[cov_full_pap]),
                  data = bilendi_survey %>% 
                    # keep only those respondents who pass attention check
                    filter(any_correct_remember_plot_fotos >= 1),
                  se = "standard")

# prepare data for plotting
pap_models <- bind_rows(
  te_pap_1 %>% map_dfr(broom::tidy, conf.int = T, .id = "id") ,
  te_pap_2 %>% map_dfr(broom::tidy, conf.int = T, .id = "id") 
) %>% 
  mutate(Covariates = ifelse(grepl("\\+", id), "with covariates", "no covariates")) %>% 
  filter(grepl("treat", term)) %>% 
  filter(grepl("afd_pref_post", id))

# build coefficient plot
main_coefficient_plot <- pap_models %>% 
  ggplot(., aes(x = term, y = estimate, 
                group = Covariates, color = Covariates)) +
  geom_vline(xintercept = 2.5) + 
  geom_hline(yintercept = 0, linetype = "dashed") +
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), 
                width = 0, linewidth = 0.25, 
                position = position_dodge(width = .5)) + 
  geom_errorbar(aes(ymin = estimate - 1.645 * std.error, 
                    ymax = estimate + 1.645 * std.error), 
                width = 0, linewidth = 0.7, 
                position = position_dodge(width = .5)) +
  geom_point(size = 3,
             position = position_dodge(width = .5)) + 
  scale_x_discrete(labels = c("factor(treatvscontrol)treatment" = "Pooled treatment", 
                              "factor(treatment)2" = "Treatment group 1\n(no media backlash)", 
                              "factor(treatment)3" = "Treatment group 2\n(with media backlash)")) +
  theme_bw() + 
  scale_color_manual("", values = c("grey60", "black")) + 
  theme(legend.position = "bottom", 
        panel.grid = element_blank(),
        axis.text.x = element_text(size = 8), 
        strip.text = element_markdown()) +
  labs(y = "Treatment effect estimate\nof right-wing attack", x = "Treatment group specification")


main_coefficient_plot

ggsave(main_coefficient_plot, filename = "./figures/figure_6_survey_experiment.pdf", 
       width = 10.5, height = 5.5, scale = 0.7)



# Figure 7: Properties of attacks & media backlash ------------------------

attack_properties_backlash <-
  rtv_cases %>% 
  mutate(
    intensity = ifelse(n_wounded > 1 | n_killed > 1, "High", "Low"),
    matching_lab = case_when(
      perp_rightwing == 1 & target_migrant == 1 ~ "Match",
      is.na(perp_rightwing) | intensity == "Low" ~ "All attacks",
      T ~ "Non-match"
    ),
    matching_lab = factor(matching_lab, c("Match", "Non-match", "All attacks")
    )
  ) %>%
  drop_na(intensity) %>%
  group_by(intensity, matching_lab) %>%
  summarise(backlash = mean(backlash), .groups = "drop") %>%
  ggplot(data = ., aes(x = intensity, y = backlash, fill = matching_lab)) +
  geom_col(color = "black", width = .5, position = position_dodge2(preserve = "single")) +
  scale_fill_manual("Match between PRRP narratives\nand victim identity / attacker motive?", values = c("grey30", "grey60", "grey90")) +
  labs(y = "Change in PRRP article share\nreferencing right-wing violence (mean)", 
       x = "Attack intensity", parse = T) +
  theme_bw() +
  theme(legend.position = "bottom", panel.grid = element_blank())

ggsave("./figures/figure_7_attack_properties_backlash.pdf", 
       attack_properties_backlash,
       width = 6.5, height = 4, scale = .9, device = cairo_pdf)

# Figure 8: Effect of attacks, 1990-2020 ----------------------------------

# Estimate models 

covariates_all <- c("bland_", 
                    "male", 
                    "education",
                    "unemployed")

## All RTV attacks

rtv_backlash_models_all <-
  feols(voting_right_wing_fed ~ post_attack + birthyear | .[covariates_all] + case_id,
        data = forsa_rtv_data %>%
          filter(time_since_attack %in% -5:4),
        split = ~backlash_cat,
        se = "hetero")

rtv_backlash_models_all_early <-
  feols(voting_right_wing_fed ~ post_attack + birthyear | .[covariates_all] + case_id,
        data = forsa_rtv_data %>%
          filter(time_since_attack %in% -5:4,
                 (year < 1995 & bland_ %in% c(8, 9)) | year >= 1995),
        split = ~backlash_cat,
        se = "hetero")

## Only matching perpetrator / victim type

rtv_backlash_models_match <-
  feols(voting_right_wing_fed ~ post_attack + birthyear | .[covariates_all] + case_id,
        data = forsa_rtv_data %>%
          filter(time_since_attack %in% -5:4,
                 perp_rightwing == 1 & target_migrant == 1,
          ),
        split = ~backlash_cat,
        se = "hetero")

rtv_backlash_models_match_early <-
  feols(voting_right_wing_fed ~ post_attack + birthyear | .[covariates_all] + case_id,
        data = forsa_rtv_data %>%
          filter(time_since_attack %in% -5:4,
                 (year < 1995 & bland_ %in% c(8, 9)) | year >= 1995,
                 perp_rightwing == 1 & target_migrant == 1),
        split = ~backlash_cat,
        se = "hetero")


# Build plot

rtv_media_backlash_coeflplot <-
  bind_rows(
    map(c(.9, .95), function(clevel) {
      
      models_tidy <- imap(rtv_backlash_models_match, function(model, spec) {
        broom::tidy(model, conf.int = T, conf.level = clevel) %>% 
          mutate(clevel = clevel,
                 backlash_cat = str_extract(spec, "(?<=sample: ).*"))
      }) %>%
        bind_rows()
      
    }) %>%
      bind_rows() %>%
      mutate(sample = "High intensity cases +\nattacker motive / victim identity\nmatching PRRP narrative"),
    map(c(.9, .95), function(clevel) {
      
      models_tidy <- imap(rtv_backlash_models_all, function(model, spec) {
        broom::tidy(model, conf.int = T, conf.level = clevel) %>% 
          mutate(clevel = clevel,
                 backlash_cat = str_extract(spec, "(?<=sample: ).*"))
      }) %>%
        bind_rows()
      
    }) %>%
      bind_rows() %>%
      mutate(sample = "All fatal attacks"),
  ) %>%
  filter(term == "post_attackTRUE") %>%
  mutate(backlash_cat = factor(backlash_cat, c("low", "high"))) %>%
  pivot_wider(names_from = "clevel", values_from = c("conf.low", "conf.high")) %>%
  ggplot(data = ., aes(x = backlash_cat, y = estimate)) +
  geom_hline(yintercept = 0, linetype = "dashed") +
  geom_pointrange(aes(ymin = conf.low_0.9, ymax = conf.high_0.9),
                  position = position_dodge(width = .5),
                  linewidth = 1,
                  size = .2) +
  geom_pointrange(aes(ymin = conf.low_0.95, ymax = conf.high_0.95),
                  position = position_dodge(width = .5),
                  linewidth = .3,
                  size = .2) +
  scale_x_discrete(labels = c("Low", "High")) +
  facet_wrap(~sample) +
  labs(x = "Media backlash", y = "Post-attack coefficient\nestimate on PRRP support") +
  theme_bw() +
  theme(legend.position = "bottom", panel.grid = element_blank())

ggsave( "./figures/figure_8_effects_all_attacks_90_20.pdf", 
        rtv_media_backlash_coeflplot,
        width = 6, height = 4, scale = .9)
